﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using cmsservice.Entity;

namespace cmsservice.DAL
{
    public class YicaiDal
    {


        public DataTable GetBSDateAndDay(int SecuCode, int PeriodType)
        {
            try
            {
                Tools tool = new Tools();
                tool.AddSqlParameter("@SecuCode", SqlDbType.Int, SecuCode);
                tool.AddSqlParameter("@PeriodType", SqlDbType.Int, PeriodType);

                string Query = @"
SELECT top 1 a.SecuCode,a.TradeDate,a.PeriodType,a.BSType,b.cpx_day,b.cpx_week,b.cpx_month,c.SecuAbbr
FROM   tb_info_yicai_bspoint a WITH(NOLOCK)
       INNER JOIN EM_CPX_STAT b WITH(NOLOCK) ON RIGHT(Cast(a.SecuCode AS VARCHAR), 6) = RIGHT(b.stock_id, 6)
       INNER JOIN [security] c WITH(NOLOCK) ON RIGHT(Cast(a.SecuCode AS VARCHAR), 6) = c.secucode AND
                                               c.secucategory IN ( '001001', '001002' ) AND
                                               ListState <> '013002'
WHERE  RIGHT(Cast(a.SecuCode AS VARCHAR), 6) = @SecuCode AND
       a.PeriodType = @PeriodType
ORDER  BY TradeDate DESC ";
                DataSet result = SqlHelper.ExecuteGetDataSet(DBConn.Yicai, CommandType.Text, Query, tool.GetSqlParameters());
                return result.Tables[0];
            }
            catch (Exception ex)
            {
                return new DataTable();
            }
        }


    }
}
